#include<iostream>
#include<string>
using namespace std;
char arr[110], temp[110];
string s;
int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < 26; i++) {
		temp[i] = 'A' + i;
		//cout << temp[i] << endl;
	}
	while (t--) {
		cin >> s;
		int idx1 = s.find("R");
		int idx2 = s.find("C");
		bool flag = 0;
		if (idx1 == -1 && idx2 == -1)flag = 1;
		else {
			if (idx2 == 1)flag = 1;
		}
		//cout << "flag==" << flag << endl;
		if(flag){
			//2
			int ans = 0;
			int ans1 = 0;
			string k;
			for (int i = 0; i < s.size(); i++) {
				if (s[i] - '0' >= 0 && s[i] - '0' <= 9)ans = ans * 10 + s[i] - '0';
				else {
					k += s[i];
				}
			}
			cout << "R" << ans << "C";
			//BCD
			int len = k.size() - 1;
			//cout << "k==" << k << endl;
			for (int i = 0; i < k.size(); i++) {
				ans1 += pow(26, len) * (k[i] - 'A' + 1);
				len--;
			}
			cout << ans1 << endl;
		}
		else {
			//1
			int ans1 = 0, ans2 = 0;
			int idx = 0;
			for (int i = 1; i < s.size(); i++) {
				if (s[i] == 'C') {
					idx = i;
					break;
				}
				ans1 = ans1 * 10 + s[i] - '0';
			}
			for (int i = idx + 1; i < s.size(); i++) {
				ans2 = ans2 * 10 + s[i] - '0';
			}
			int m = 0;
			while (ans2) {
				arr[m++] = temp[ans2 % 26 - 1];
				ans2 /= 26;
			}
			for (int i = m - 1; i >= 0; i--) {
				cout << (char)arr[i];
			}
			cout << ans1 << endl;
		}
	}
	return 0;
}